public class Th1 {
    public static void main(String[] args) {
        Object count=20;
        Thread test1=new Thread(()->{
            synchronized (count){
                for(int i=0;i<Integer.valueOf((Integer) count);i++){
                    System.out.println(i);
                    try {
                        Thread.sleep(4);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread test2=new Thread(()->{
            synchronized (count){
                for(int i=0;i<Integer.valueOf((Integer)count);i++){
                    System.out.println(i+"test2");
                }
            }
        });
        test1.start();
        test2.start();

    }
    public static void main2(String[] args) throws InterruptedException {
        int  count=10;
        int len=0;
        Thread a=new Thread(()->{
                for(int i = 0; i<count; i++){
                    System.out.println(i);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
        });
        Thread b=new Thread(()->{
            for(int i=count;i<2*count;i++){
                System.out.println(i);
                try {
                    Thread.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        a.start();
        b.start();

    }

    public static void main1(String[] args) {
        Object lajiyou = new Object();
        Object cu = new Object();
        Thread me = new Thread(() -> {
            synchronized (lajiyou) {
                System.out.println("me拿到了辣椒油");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (cu) {
                    System.out.println("me拿到了醋");
                }
            }
        });
        Thread you = new Thread(() -> {
            synchronized (cu) {
                System.out.println("you拿到了醋");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lajiyou) {
                    System.out.println("you拿到了辣椒油");
                }
            }
        });
        me.start();
        you.start();
    }
}
